********************************************************************************
** 	TITLE: e13_fs_binscatter.do
**
**	PROJECT: IGNITE
** 
**  PURPOSE: Appendix Figure XIII: First-Stage Effects of Court Delays by Booking Month
**
********************************************************************************
		set sortseed 13
		use "$output_data/estimate.dta", clear

**Binned scatter			
			//stay ignite_0 for stay analyses
				cap drop stay
				gen stay = stay_rec
				cap drop ignite_0
				gen ignite_0 = ignite_0_rec
				local cond ""
	
//FS Regression			
				reghdfe stay i.ym_booked#D_remove_any i.ym_booked $auxiliary_control `cond' ,  a($design_control) 

				mat define R=J(200,2,.)
				forvalues j=662/755{
					cap mat R[`j'-661,1] = _b[`j'.ym_booked#1.D_remove_any]
					cap mat R[`j'-661,2] = `j'
				}
				
				preserve 
				keep if e(sample)==1
				collapse (count) bin_size = booking_date, by(ym_booked)
				ren ym_booked ym
				
				tempfile size
				save `size'
				
				restore
				
				preserve
				svmat R
				ren (R1 R2 ) (c ym)
				keep c ym
				keep if !mi(c)
				
				merge 1:1 ym using `size', nogen
				
				lpoly c ym if ym<728 [aw=bin_size], nograph  generate(g1 s1) se(se1) bwidth(14) d(1)
				lpoly c ym if ym>=728 [aw=bin_size] , nograph  generate(g2 s2) se(se2) bwidth(14) d(1)


				forvalues j=1/2{
					gen ul`j' = s`j'+1.96*se`j'
					gen ll`j' = s`j'-1.96*se`j'
				}
				local xl  xline(728, lc(gs8) lp(solid) lwidth(*1.3))  yline(0,lc(black))
				local xlab xlab(672(18)744 , format(%tm) labsize(*.9))
				
				
					local title "Months in jail"
					local ylab ylab(-1(1)2,labsize(*.9))
					local text text(1.6 735.9 "Start of IGNITE", size(*.85))
										
//Bin Scatter Plots					
				tw 	(scatter  c ym if ym<728 , sort mc(%80) mc("31 119 180") msymbol(Dh)) ///msymbol(Dh Oh)
					(scatter  c ym if ym>=728, sort mc(%80) mc(maroon) msymbol(Oh)) ///
					(rarea ul1 ll1 g1 , sort fc(ebblue%30) lc(%0)) ///
					(rarea ul2 ll2 g2 , sort fc(maroon%30) lc(%0) ) ///
					(line s1 g1 , sort lc(ebblue) lwidth(medium)) ///
					(line s2 g2 , sort lc(maroon) lwidth(medium)) ///
					, ///
					legend(off) `xl' ///735
					xtitle("Booking month") ytitle("`title'") ///
					`ylab' `xlab' `text'
				
				graph export "$figures/bin_scatter_stay.pdf", replace
				restore
